﻿<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="zh">
<head>
<%@include file="../../commons/meta.jsp"%>
<c:set var="baseUrl" value="${ctx}api/university-majors/" scope="request" />
<link rel="stylesheet" href="${ctx}assets/plugins/pure/pure-min.css" media="all" />
</head>
<body>
    <%@include file="../../commons/head.jsp"%>
    <div class="content">
        <%@include file="../../commons/menu.jsp"%>
        <div class="right-zq">
            <!--center content-->
            <div class="dynamic">
                <form id="listForm" action="${baseUrl}" method="post">
                    <div class="role dynamiclayer" style="display: block;">
                        <div class="title orange2">
                            <span class="left"><fmt:message key="college.data.manage" /></span> <label> > </label> <span>学校专业管理</span>
                        </div>
                        <div class="role-input role-input2">
                            <!-- role-input2 role-input3 -->
                            <ul class="input">
                                <li class="p33">学校名称： <input type="text" name="searchMap.universityName,like,string" value="" class="input1 num" maxlength="4" />
                                </li>
                                <li class="p33">专业代码： <input type="text" name="searchMap.majorCode,like,string" value="" class="input1" maxlength="36" />
                                </li>
                                <li class="p33">专业名称： <input type="text" name="searchMap.majorName,like,string" value="" class="input1" maxlength="36" />
                                </li>
                            </ul>
                            <div class="button">
                                <span class="orange2" onclick="listFormPageSearch(1)">查询</span>
                                <s:authorize access="hasAuthority('college:major:add')">
                                    <span class="orange2"><a href="${baseUrl}add">添加</a></span>
                                </s:authorize>
                                <s:authorize access="hasAuthority('college:major:import')">
                                    <span class="orange2"><a href="${baseUrl}import">导入</a></span>
                                </s:authorize>
                            </div>
                        </div>
                        <div class="role-table role-table2">
                            <table cellspacing="0px" id="datatable">
                            </table>
                        </div>
                        <div class="role-page">
                            <input type="hidden" id="pageSize" name="pageSize" value="10" />
                            <ul id="datapagefoot">
                            </ul>
                        </div>
                    </div>
                </form>
            </div>
            <!--center content over-->
        </div>
    </div>
    <script type="text/javascript">
 var defaultPageFoot = '';
 defaultPageFoot += '<li><a class="first orange2-text" id="firstPage" href="javascript:void(0);"><fmt:message key="sys.home"/></a></li>';
 defaultPageFoot += '<li>共<label class="num"  id="pagesPageCount">0</label>页，每页<label class="num">10</label>条，';
 defaultPageFoot += '到第<input type="text" id="pageNumers" name="pageNumber" value="1" maxlength="9" onpaste="return false;" class="num" />页';
 defaultPageFoot += '<span class="confirm orange2-text orange2-border"  onclick="listFormPageSearch(1)"><fmt:message key="determine"/></span></li>';

 /**分页查询*/
 function listFormPageSearch(pageNum) {
  var pageForm = $("#listForm").serializeObject();
  var pageCounts = $("#pageCounts").val();
  checkPageNumber(pageForm, pageNum);

  var searchMap = [];
  $.each(pageForm, function (name, value) {
   if (name.indexOf('searchMap') >= 0) {
    var searchMapMeta = {};
    delete pageForm[name];
    var name2 = name.replace("searchMap.", "");
    searchMapMeta[name2] = value;
    searchMap.push(name2 + "," + value);
   }
  });
  pageForm.searchList = searchMap;
  // 默认按照专业分类代码排序
  pageForm.sort="universityName";
  debugs("pageForm after" + pageForm);
  var searchJsonUrl = '${baseUrl}page.json';
  var pageData = JSON.stringify(pageForm);
  debugs("ajax pageData 2: " + pageData);
  var tableHead = ['序号','学校名称','专业代码','专业名称','操作'];

  var tableHtml = getHead(tableHead);
  $.ajax({
   url: searchJsonUrl + "?rand=" + Math.random(),
   data: pageData,
   type: 'POST',
   contentType: "application/json",
   dataType: 'json',
   success: function (pages) {
     var base = pages.pageSize*(pages.pageNumber-1);
    var tr = "";
    $.each(pages.rows, function (index, item) {
     var trtmp = getValueTr([
       (base+index+1),
       filtUndef(item.universityName),
      filtUndef(item.majorCode),
      filtUndef(item.majorName),
      <s:authorize access="hasAuthority('major_type:update')">
      '&nbsp;&nbsp;<a href="javascript:void(0);" onclick="mod(' + item.id + ')">修改</a>' +
      </s:authorize>
      <s:authorize access="hasAuthority('major_type:delete')">
      '&nbsp;&nbsp;<a href="javascript:void(0);" onclick="del(' + item.id + ')">删除</a>' +
      </s:authorize>
      '']);
     tr += trtmp;
    });
    if (isEmpty(tr)) {
     tr = "<tr><td colspan='" + tableHead.length + "' class='error'><fmt:message key='Temporarily.no.data'/></td></tr>";
    }

    $("#datatable").html(tableHtml + tr);
    $("#pageSize").val(pages.pageSize);
    $("#datapagefoot").html(getPageFoot(pages));
    //解决当上次查询无数据时，弹出 “请输入合理的页码范围!”提示
    if ($("#pageCounts").val() == "0") {
     $("#pageCounts").val("");
    }
   }, error: function (xhr) {
    alertError("<fmt:message key='sys.message.searcherror'/>");//请求失败遇到异常触发
    $("#datapagefoot").html(getDefaultPageFoot());
   }
  });
 }
 listFormPageSearch(1);
 
 // 初始化时加载学科下拉框数据
 getMajorSubject();
 /**
  * 获取学科
  * @returns
  */
 function getMajorSubject() {
   // 默认按id排序
   var query = {};
   // 学科的父级代码默认为"00"
   query.parentCode = "00";
   var searchJsonUrl = 'api/major-types/findAll';
   var param = JSON.stringify(query);

   $.ajax({
    url: searchJsonUrl,
    data: param,
    type: 'POST',
    contentType: "application/json",
    dataType: 'json',
    success: function (result) {
      debugs(result);
      var list = result.list;
      if (list.length > 0) {
        var option = "<option value=''>全部</option>";
        $.each(list, function(index, item) {
          option += "<option code='" + item.majorTypeCode + "' value='" + item.majorTypeCode + "'>" + item.majorTypeName + "</option>";
        });
        $("#majorSubject").html(option);
      }
    }, 
    error: function (xhr) {
      alertError("系统异常，请联系管理员！");// 请求失败遇到异常触发
    }
   });
 }
</script>
    <%@include file="../../commons/footpop.jsp"%>
</body>
</html>
